<template>
  <div class="editable-cell">
    <div class="editable-cell-input-wrapper">
      <a-input :value="value" :disabled="disabled" @change="handleChange" @blur="check" @pressEnter="check" />
    </div>
  </div>
</template>

<script>
export default {
  name: 'EditableCell2',
  props: {
    text: String,
    disabled: Boolean,
  },
  data() {
    return {
      value: this.text,
    }
  },
  watch:{
      text: {
        immediate: true,
        handler(val) {    
          this.value=val
        }
      },
    },
  methods: {
    handleChange(e) {
      const value = e.target.value
      this.value = value
    },
    check() {
      this.$emit('change', this.value)
    },
  },
}
</script>

<style scoped>
.editable-cell {
  position: relative;
}

.editable-cell-input-wrapper,
.editable-cell-text-wrapper {
  padding-right: 1px;
}

.editable-cell-text-wrapper {
  padding: 2px 2px 2px 2px;
}

.editable-cell-icon,
.editable-cell-icon-check {
  position: absolute;
  right: 0;
  width: 20px;
  cursor: pointer;
}

.editable-cell-icon {
  line-height: 18px;
  /*display: none;*/
}

.editable-cell-icon-check {
  line-height: 28px;
}

.editable-cell:hover .editable-cell-icon {
  display: inline-block;
}

.editable-cell-icon:hover,
.editable-cell-icon-check:hover {
  color: #108ee9;
}

.editable-cell .ant-input {
  width: 100%;
  /*margin: 0 8px 8px 0;*/
}
</style>
